package com.jstyle.jclifexd.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.jstyle.jclifexd.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/9/20.
 */

public class FeedBackAdapter extends RecyclerViewBaseAdapter<String> {


    public FeedBackAdapter(List<String> mList) {
        super(mList);
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {

    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_feedback;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ClockModeViewHolder(getInflaterView(parent, viewType));
    }

    List<Integer> checkedList = new ArrayList<>();

    @Override
    public void onBindViewHolder(BaseViewHolder holder, final int position) {
        ClockModeViewHolder clockModeViewHolder = (ClockModeViewHolder) holder;
        clockModeViewHolder.btClockModeName.setText(mDataList.get(position));
        clockModeViewHolder.btClockModeName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (checkedList.contains(position)) {
                    checkedList.remove(checkedList.indexOf(position));
                } else {
                    checkedList.add(position);
                }
                notifyDataSetChanged();
            }
        });
        Context context = clockModeViewHolder.itemView.getContext();


        int visibility=View.VISIBLE;
        boolean clickable=true;
        if (position == 0 || position == 17 || position == 26) {

            clockModeViewHolder.btClockModeName.setTextColor(Color.parseColor("#999999"));
            visibility=View.GONE;
            clickable=false;
        } else {
            clockModeViewHolder.btClockModeName.setTextColor(Color.BLACK);

            clockModeViewHolder.btClockModeName.setBackgroundColor(Color.WHITE);
        }
        clockModeViewHolder.viewSpace.setVisibility(visibility);
        clockModeViewHolder.btClockModeName.setClickable(clickable);

        setDrawable(clockModeViewHolder, position);

    }

    private void setDrawable(ClockModeViewHolder clockModeViewHolder, int position) {
        int id = R.drawable.clock_mode_checked;
        Context context = clockModeViewHolder.itemView.getContext();
        Drawable drawable = context.getResources().getDrawable(id);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        clockModeViewHolder.btClockModeName.setCompoundDrawables(null, null, checkedList.contains(position) ? drawable : null, null);

    }
    public String getCheckedInfo(){
        String info="";
        for(Integer integer:checkedList){
            info=info+mDataList.get(integer)+";";
        }
        return TextUtils.isEmpty(info)?info:info.substring(0,info.length()-1);
    }
    public class ClockModeViewHolder extends BaseViewHolder {

        @BindView(R.id.bt_feedback)
        Button btClockModeName;
        @BindView(R.id.view_space)
        View viewSpace;

        public ClockModeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
